const {
  $util,
} = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    page: 1,
    navPage: 1,
    hasMore: true,
    navList: [],
    curId: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(ops) {
    this.setData({
      curId: ops.id || '',
      showNav: ops.flg == 1 ? false : true,
    });
    if (ops.flg == 1) {
      this.getList();
    } else {
      this.getNav();
    }
    wx.setNavigationBarTitle({
      title: ops.barTitle && decodeURIComponent(ops.barTitle) || '活动剪影',
    });
  },
  getNav() {
    $util.request({
      url: 'entry/wxapp/edu.incorruptgov.getactivitycate',
      data: {
        page: this.data.navPage,
      },
      success: (res) => {
        let navList = res.list;
        navList = [...[{
          id: '',
          classifyname: '全部', 
          picture: '',
        }], ...navList];
        this.setData({
          navList,
          isloadmore: res.total > navList.length,
          navPage: res.total > navList.length ? ++this.data.navPage : this.data.navPage,
        });
        this.getList();
      },
    });
  },
  changeTab(e) {
    this.setData({
      curId: e.detail.obj.id,
      page: 1,
      isLoad: false,
    });
    this.getList();
  },
  navmore() {
    this.getNav();
  },
  getList() {
    $util.request({
      url: 'entry/wxapp/edu.incorruptgov.getactivity',
      data: {
        page: this.data.page,
        classifyid: this.data.curId,
      },
      showLoading: false,
      success: (res) => {
        let list = res.list;
        if (this.data.page > 1) {
          list = [...this.data.list, ...list];
        }
        this.setData({
          list,
          hasMore: res.list.length !== 0,
          page: res.list.length !== 0 ? this.data.page + 1 : this.data.page,
          isLoad: true,
        });
      },
    });
  },
  onReachBottom() {
    this.data.hasMore && this.getList();
  },
  onShareAppMessage() {
    let _this = this;
    let path = '/ws_party_const/pages/education/probity/activity/index';
    let res = {
      path,
    };
    return res;
  },
});
